﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.Rendering;


namespace YYPostProcessing
{
    public class YYPostProcessRenderContext
    {


        Camera m_Camera;

        YYPostProcessRenderContext m_CurrentContext;

        public Camera camera
        {
            get { return m_Camera; }

            set {
                m_Camera = value;

                width = m_Camera.pixelWidth;
                height = m_Camera.pixelHeight;

                screenWidth = width;
                screenHeight = height;

            }
        }


        public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID,int depthBufferBits = 0, 
            RenderTextureFormat colorFormat = RenderTextureFormat.Default, 
            RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default,
            FilterMode filter = FilterMode.Bilinear, int widthOverride = 0, int heightOverride = 0)
        {
            int width = screenWidth;
            int height = screenHeight;

            if (widthOverride > 0)
                width = widthOverride;
            if (heightOverride > 0)
                height = heightOverride;

            cmd.GetTemporaryRT(nameID, width, height, depthBufferBits, filter
                , colorFormat, readWrite);

        }

        public void Reset()
        {
            m_Camera = null;
            width = 0;
            height = 0;

            screenWidth = 0;
            screenHeight = 0;

            command = null;
            source = 0;
            destination = 0;
            sourceFormat = RenderTextureFormat.ARGB32;

            resources = null;
        }

        public YYPostProcessResources resources { get; internal set; }


        public RenderTextureFormat sourceFormat { get; set; }


        public CommandBuffer command { get; set; }


        public RenderTargetIdentifier source { get; set; }


        public RenderTargetIdentifier destination { get; set; }

        public YYPropertySheetFactory propertySheets { get; internal set; }


        public int width { get; private set; }

        /// <summary>
        /// The current camera height (in pixels).
        /// </summary>
        public int height { get; private set; }

        public int screenWidth { get; private set; }

        /// <summary>
        /// The height of the logical screen size.
        /// </summary>
        public int screenHeight { get; private set; }
    }
}
